package model

import (
	"fmt"

	"github.com/astaxie/beego/logs"
	"github.com/go-xorm/core"
)

type Logger struct {
	BeeLogger *logs.BeeLogger
	showSql   bool
}

func NewLogger(beeLogger *logs.BeeLogger) *Logger {
	return &Logger{BeeLogger: beeLogger}
}

func (l *Logger) Debug(v ...interface{}) (err error) {
	s := fmt.Sprintln(v...)
	l.Debugf(s)
	return err
}

func (l *Logger) Debugf(format string, v ...interface{}) (err error) {
	l.BeeLogger.Debug(format, v)
	return err
}

func (l *Logger) Err(v ...interface{}) (err error) {
	s := fmt.Sprintln(v...)
	l.Errf(s)
	return err
}

func (l *Logger) Errf(format string, v ...interface{}) (err error) {
	l.BeeLogger.Error(format, v)
	return err
}

func (l *Logger) Info(v ...interface{}) (err error) {
	s := fmt.Sprintln(v...)
	l.Infof(s)
	return err
}

func (l *Logger) Infof(format string, v ...interface{}) (err error) {
	l.BeeLogger.Informational(format, v)
	return err
}

func (l *Logger) Warning(v ...interface{}) (err error) {
	s := fmt.Sprintln(v...)
	l.Warningf(s)
	return err
}

func (l *Logger) Warningf(format string, v ...interface{}) (err error) {
	l.BeeLogger.Warning(format, v)
	return err
}

func (l *Logger) Level() core.LogLevel {
	return core.LOG_UNKNOWN
}

func (l *Logger) SetLevel(level core.LogLevel) (err error) {
	l.BeeLogger.SetLevel(int(level))
	return err
}

func (l *Logger) ShowSQL(show ...bool) {
	if len(show) > 0 {
		l.showSql = show[0]
	} else {
		l.showSql = false
	}
}

func (l Logger) IsShowSQL() bool {
	return l.showSql
}
